package Method;

/**
 * @author 王艺锡
 * @version 1.0
 */
public class ThreadMethod {
    public static void main(String[] args) throws InterruptedException {
        T t = new T();
        //设置线程的优先级为最小
        t.setPriority(Thread.MIN_PRIORITY);
        t.setName("yx");
        t.start();

        for (int i = 0;i<5;i++){
            Thread.sleep(1000);
            System.out.println("主线程休眠中" + (i+1));
        }

        System.out.println(t.getName() + "的优先级为" + t.getPriority());
        //中断休眠中的子线程
        t.interrupt();



    }
}

class T extends Thread {

    @Override
    public void run() {
        while (true) {
            for (int i = 1; i <= 100; i++) {
                System.out.println(Thread.currentThread().getName() + "干饭*" + i);
            }

            try {
                System.out.println(Thread.currentThread().getName() + "休眠中");
                Thread.sleep(20000);
            } catch (InterruptedException e) {
                //当线程执行到一个interrupt方法时，就会catch一个异常
                System.out.println(Thread.currentThread().getName() + "被interrupt");

            }
        }


    }
}

